package com.p2p.front.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.p2p.base.page.PageVo;
import com.p2p.front.dal.dao.IdCardDao;
import com.p2p.front.dal.model.AuthValue;
import com.p2p.front.dal.model.IdCardInfo;
import com.p2p.front.dal.model.LoanInfo;
import com.p2p.front.service.IdCardService;
import com.p2p.front.service.UserInfoAuthService;
import com.p2p.front.web.form.LoanForm;
import com.p2p.user.enums.UserAuthName;

@Service("idCardService")
public class IdCardServiceImpl implements IdCardService {
	
	@Resource
	private IdCardDao idCardDao;
	
	@Resource
	private UserInfoAuthService userInfoAuthService;
	
	@Override
	public void saveIdCard(IdCardInfo idCard) {
		idCardDao.save(idCard);
	}
	@Override
	public PageVo listAll(PageVo form) {
		List<IdCardInfo> list= idCardDao.listPageBackend(form);
		form.setList(list);
		return form;
	}
	@Override
	public IdCardInfo getByUid(String uid) {
		return idCardDao.getByUid(uid);
	}
	public IdCardInfo getAuthing(String uid) {
		return idCardDao.getAuthing(uid);
	}
	
	@Override
	@Transactional
	public void updateIdCardStatus(IdCardInfo idCard) {
		idCardDao.updateIdCardStatus(idCard);
		List<AuthValue> list = new ArrayList<AuthValue>();
		int status = idCard.getStatus();
		char auth ='0';
		if(status == 1){
			auth='1';
			AuthValue authValue = new AuthValue(UserAuthName.AUTH_REALNAME,auth);
			list.add(authValue);
			userInfoAuthService.saveAuthByAuthValueList(idCard.getUid(), list);
		}
		
	}
}
